# Contributor: Siva Mahadevan <me@svmhdvn.name>
# Contributor: Simon Frankenberger <simon-alpine@fraho.eu>
# Maintainer: Simon Frankenberger <simon-alpine@fraho.eu>
pkgname=signal-cli
pkgver=0.12.6
pkgrel=0
pkgdesc="commandline interface for libsignal-service-java"
url="https://github.com/AsamK/signal-cli"
# jdk17 only available on 64 bit archs
# cargo and rust not available on s390x and riscv64
# java-libsignal-client not available on aarch64
# ppc64le: no openjdk17-jdk
arch="x86_64"
license="GPL-3.0-or-later"
depends="java-libsignal-client"
makedepends="openjdk17-jdk"
source="$pkgname-$pkgver.tar.gz::https://github.com/AsamK/signal-cli/archive/v$pkgver.tar.gz"

build() {
	./gradlew installDist
}

check() {
	./gradlew check
}

package() {
	local buildhome="build/install/$pkgname"
	local installhome="/usr/share/java/$pkgname"

	install -dm755 "$pkgdir/$installhome/lib"
	install -m644 "$buildhome"/lib/* "$pkgdir/$installhome/lib"

	install -Dm755 "$buildhome/bin/$pkgname" "$pkgdir/$installhome/bin/$pkgname"
	install -dm755 "$pkgdir/usr/bin"
	ln -s "$installhome/bin/$pkgname" "$pkgdir/usr/bin/$pkgname"

	rm -v "$pkgdir/$installhome/lib"/libsignal-client-*.jar
	ln -sv /usr/share/java/libsignal-client/signal-client-java.jar "$pkgdir/$installhome/lib/signal-client-java.jar"
	sed -i -e 's/libsignal-client-[0-9.]\+\.jar/signal-client-java.jar/g' "$pkgdir/$installhome/bin/$pkgname"
}

sha512sums="
92ae359e02d40898258af9c782a1873fafef65f652a63e0d661cf3e462c6204d0179f9971adcbd1c0c681ea58c051b6480a28ad2a6c703cfd4f48890ec606eb5  signal-cli-0.12.6.tar.gz
"
